<?php
namespace Home\Controller;

use Think\Controller;

class IndexController extends Controller
{
    public function index()
    {
        $deptID = I("get.deptid");
        $p = empty($_GET['p']) ? 1 : $_GET['p'];
        $enroll = D('EnInfo'); // 实例化User对象
        if (empty($deptID) | $deptID == 0) {
            $res = $enroll->order('addtime desc')->page($p . ',10')->where("issue=1")->select();
            //        dump($res);
            $count = $enroll->where("issue=1")->count();// 查询满足要求的总记录数

            $Page = new \Think\Page($count, 10);// 实例化分页类 传入总记录数和每页显示的记录数
            $Page->setConfig('prev', '<li class="waves-effect"><i class="mdi-navigation-chevron-left"></i></li>');
            $Page->setConfig('next', '<li class="waves-effect"><i class="mdi-navigation-chevron-right"></i></li>');
            $Page->setConfig('first', '<li class="waves-effect"><i class="material-icons">1</i></li>');
            $Page->setConfig('last', '<li class="waves-effect"><i class="material-icons">%TOTAL_PAGE%</i></li>');
            $Page->setConfig('theme', '%UP_PAGE% %FIRST% %LINK_PAGE% %DOWN_PAGE% %END%');
            $show = $Page->show();// 分页显示输出
        } else {
            $map['issue'] = 1;
            $map['deptid'] = $deptID;
            $res = $enroll->order('addtime desc')->page($p . ',10')->where($map)->select();
            //        dump($res);
            $count = $enroll->where($map)->count();// 查询满足要求的总记录数

            $Page = new \Think\Page($count, 10);// 实例化分页类 传入总记录数和每页显示的记录数
            $Page->setConfig('prev', '<li class="waves-effect"><i class="mdi-navigation-chevron-left"></i></li>');
            $Page->setConfig('next', '<li class="waves-effect"><i class="mdi-navigation-chevron-right"></i></li>');
            $Page->setConfig('first', '<li class="waves-effect"><i class="material-icons">1</i></li>');
            $Page->setConfig('last', '<li class="waves-effect"><i class="material-icons">%TOTAL_PAGE%</i></li>');
            $Page->setConfig('theme', '%UP_PAGE% %FIRST% %LINK_PAGE% %DOWN_PAGE% %END%');
            $show = $Page->show();// 分页显示输出
        }

        $this->assign("res", $res);// 赋值分页输出
        $this->assign('page', $show);
        $this->display(); // 输出模板
    }


}